<template>
	<view style="background-color: #FFFFFF;height: 100vh;">
		<hx-navbar ref="hxnb" :config="config" />
		<view class="flex flex-direction justify-center align-center" style="margin-top: 100rpx;">
			<view style="height:400rpx;width: 400rpx;">
				<x-lottie style="width:100%;height:100%;" :option="{
			 	                path:path[type],
								loop:loop
			 	}" />
			</view>
			<view style="margin-top: 40rpx;">你的当前身份是"{{role[type]}}"</view>
			<view class="butterns" @tap="role1">切换为{{role[typeTwo]}}身份</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				config: {
					title: '',
					color: '#111111',
					backgroundColor: [1, '#FFFFFF'],
					border: true,
					// #ifdef H5
					backPage: '',
					// #endif
				},
				// 是否循环
				loop: true,
				// 当前身份
				type: null,
				// 选择要切换的身份
				typeTwo: null,
				phone: null,
				path: {
					1: require('../../static/sheji.json'),
					2: require('../../static/anzhuang.json'),
					3: require('../../static/anzhuang.json'),
					4: require('../../static/yonghu.json')
				},
				role: {
					1: '设计',
					2: '工厂',
					3: '安装',
					4: '业主'
				}
			}
		},
		onLoad() {
			this.type = this.$cache.get('type')
			this.type == 4 ? this.myRole() : this.typeTwo = 4
			this.phone = this.$cache.get('phone')
		},
		methods: {
			role1() {
				let data = {
					type: this.typeTwo,
					phone: this.phone
				}
				this.$api.role(data).then((res) => {
					console.log('现在才醒在', res)
					this.$cache.set('type', res.data.result.type)
					this.$cache.set('token', res.data.result.token)
					this.$cache.set('id', res.data.result.id)
					console.log('现在', this.$cache.get('id'))
					this.$cache.set('name', res.data.result.name)
					this.$cache.set('avatar', res.data.result.avatar)
					this.$tools.showToast('切换成功')
					let roleType = this.$cache.get('type')
					console.log(roleType, '在创造性操作')
					switch (roleType) {
						case 1:
							uni.setTabBarItem({
								index: 0,
								text: "接单",
								visible: true,
								iconPath: '/path/to/iconPath',
								selectedIconPath: '/path/to/selectedIconPath',
								pagePath: "/pages/tabbar/clientEndTabbar/designerHome",
							})
							break
						case 2:
							console.log(2222222)
							uni.setTabBarItem({
								index: 0,
								text: "新图纸",
								visible: true,
								iconPath: '/path/to/iconPath',
								selectedIconPath: '/path/to/selectedIconPath',
								pagePath: "/pages/tabbar/clientEndTabbar/factoryHome",
							})
							break
						case 3:
							uni.setTabBarItem({
								index: 0,
								text: "安装",
								visible: true,
								iconPath: '/path/to/iconPath',
								selectedIconPath: '/path/to/selectedIconPath',
								pagePath: "/pages/tabbar/clientEndTabbar/installHome",
							})
							break
						case 4:
							uni.setTabBarItem({
								index: 0,
								text: "首页",
								visible: true,
								iconPath: '/path/to/iconPath',
								selectedIconPath: '/path/to/selectedIconPath',
								pagePath: "/pages/tabbar/clientEndTabbar/ClientHome",
							})
							break
						default:
							break
					}
					setTimeout(() => {
						uni.navigateBack()
					}, 100)
				})
			},
			myRole() {
				this.$api.myRole().then((res) => {
					this.typeTwo = res.data.result
				})
			}
		}
	}
</script>

<style scoped>
	.butterns {
		width: 630rpx;
		height: 100rpx;
		background: #492D22;
		border-radius: 20rpx;
		opacity: 1;
		position: fixed;
		bottom: 0;
		margin-bottom: 10rpx;
		color: #FFFFFF;
		line-height: 100rpx;
		text-align: center;
	}
</style>